# 设计类的实例
# 5
# class Person:
#
#     def __init__(self,name,age,height):
#         self.name=name
#         self.age=age
#         self.height=height
#
#     def __str__(self):
#         return '%s 今年 %d 岁，身高 %.2f m' % (self.name, self.age, self.height)
#
#     def run(self):
#         print('%s 跑完步，会去吃东西' % self.name)
#
#     def eat(self):
#         print('%s 不跑步，喜欢吃东西' % self.name)
#
#
# xiaoming = Person('xiaoming',18,1.75)
# xiaomei = Person('xiaomei',17,1.65)
# print(xiaoming)
# xiaoming.run()
# print(xiaomei)
# xiaomei.eat()


# 6
# class Animal:
#
#     def __init__(self,color,kind,name):
#         self.color=color
#         self.kind=kind
#         self.name=name
#
#     def __str__(self):
#         return '一只%s的%s叫%s' % (self.color,self.kind,self.name)
#
#     def jiao(self):
#         print('%s具有汪汪叫行为' % self.name)
#
#     def yao(self):
#         print('%s具有摇尾巴行为' % self.name)
#
#
# wangwang=Animal('黄颜色','狗狗','汪汪')
# print(wangwang)
# wangwang.jiao()
# wangwang.yao()


# 房子和家具的实例
# class HouseItem:
#
#     def __init__(self,name,area):
#         self.name=name
#         self.area=area
#
#     def __str__(self):
#         return '%s占地面积%.2f平方米' % (self.name,self.area)
#
# class House:
#
#     def __init__(self,kind,area):
#         self.kind=kind
#         self.area=area
#         self.s_area=area
#         self.itemlist=[]
#
#     def __str__(self):
#         return '房子的户型是%s，总面积%.2f，剩余面积%.2f，家具名称列表为%s' % (self.kind,self.area,self.s_area,self.itemlist)
#
#     def add_item(self,item):
#         print('要添加%s\t' % item)
#         if self.s_area > item.area:
#             self.itemlist.append(item.name)
#             self.s_area -= item.area
#         else:
#             print('空间不够')
#
#
# bed = HouseItem('席梦思',4)
# chest = HouseItem('衣柜',2)
# table = HouseItem('餐桌',1.5)
# print(bed)
# print(chest)
# print(table)
# house = House('海景房',60)
# house.add_item(bed)
# house.add_item(chest)
# house.add_item(table)
# print(house.itemlist)
# print(house)


# 私有属性和私有方法
# class Women:
#
#     def __init__(self,name):
#         self.name=name
#         self.__age=16
#
#     def love(self):
#         self.__secert()
#
#     def __secert(self):
#         print('%s今年%d岁' % (self.name,self.__age))
#
#
# xiaomei=Women('小美')
# xiaomei.love()



# 继承 重写(super)
# class Animal:
#
#     def eat(self):
#         print('chi')
#
#     def sleep(self):
#         print('shui')
#
#
# class Dog(Animal):
#     def play_with(self):
#         print('和人类玩耍')
#
#
# class xiaotianquan(Dog):
#     def play_with(self):
#         super(xiaotianquan, self).play_with()
#         print('和二郎神玩耍')
#
#
# wangchai=Dog()
# wangchai.sleep()
# wangchai.play_with()
#
# lili=xiaotianquan()
# lili.sleep()
# lili.play_with()


# 子类继承父类中的私有属性和私有方法
# class Father:
#     def __init__(self):
#         self.__moneynum=999
#         self.num=100
#
#     def __money(self):
#         print('小金库在箱子里')
#
#     def life(self):
#         print('生活幸福')
#         self.__money()
#
#
# class Son(Father):
#     def find(self):
#         print(self.num)
#         self.life()
#
#
#
# liyang=Son()
# liyang.find()
# # 下面这样在外部调用life也行，上面这样在子类里面调用life也行
# liyang.life()


# 多重继承 mro的使用
# class A:
#     def demo(self):
#         print('a')
#
# class B:
#     def demo(self):
#         print('b')
#
# class C(A,B):
#     def __init__(self):
#         self.num=1
#
#     # def demo(self):
#     #     # print('c')
#
#
# print(C.__mro__) # 根据c,a,b,默认基类的顺序，c没有demo方法，就会调用a的demo方法
# c=C()
# c.demo() # 根据c,a,b,默认基类的顺序，c没有demo方法，就会调用a的demo方法


class Dog:
    def __init__(self,name):
        self.name=name

    def game(self):
        print('%s玩耍'% self.name)

class Wangchai(Dog):
    def game(self):
        print('%s傻呼呼的玩耍'% self.name)

class Person:
    def __init__(self,name):
        self.name=name

    def play(self,dog):
        print('%s和%s玩耍'%(self.name,dog.name))

        dog.game()

wangwang=Wangchai('旺旺')
xiaotianquan=Wangchai('哮天犬')
liyang=Person('小李')
xiaomei=Person('小美')

liyang.play(wangwang)
print()
liyang.play(xiaotianquan)

print()
xiaomei.play(wangwang)
